﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>1.基本视图语法</title>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shCore.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushCSharp.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushXml.js"></script>
    <link type="text/css" rel="stylesheet" href="../../Content/highlighter/styles/shCoreDefault.css" />
    <script type="text/javascript">SyntaxHighlighter.all();</script>
</head>
<body>
	<h3>基本视图语法</h3>
    <pre class="brush: csharp;">
        //1、<%%>中可直接写csharp代码.
        <% int a=0; %>
        //2、<%= %>输出
        <%=a %>
        //3、ViewBag.变量名(访问控制器中的变量)
        <%=ViewBag.title%>
    </pre>

    <br />
    <p>在视图中可以直接输出控制器方法内的变量以及方法中的参数</p>
    <pre class="brush: csharp;">
    public class IndexController:Controller
    {
        public void Index(string name)
        {
            string word="hello ";
            View("Index.aspx");
        }
    }
    </pre>
    <p>
        则在视图中可以直接调用相关变量,如下:
    </p>
    <pre class="brush: csharp;">
        //当我调用Index/name/Lucas.htm时
        //输出hello Lucas
        <%=ViewBag.word%><%=ViewBag.name%>
    </pre>
</body>
</html>
